<?php

class FileUploadLogic {

    private $fileupload_query;

    public function __construct() {
        $this->fileupload_query = DB::table('file_upload');
    }

    public function insertItem($filename, $uuid, $flag = 1) {
        $ret = $this->fileupload_query->insert(
                array(
                    'filename' => $filename,
                    'uuid' => $uuid,
                    'flag' => $flag,
                )
        );
        return $ret;
    }

    public function updateItem($uuid, $flag = 3) {
        $ret = $this->fileupload_query->where('uuid', '=', $uuid)->update(
                array(
                    'flag' => $flag,
                    'mtime' => time(),
                )
        );
        $item = DB::table('file_upload')->where('uuid', '=', $uuid)->first();
        $filename = $item->filename;
        $file_uuid = $item->uuid;
        $videoLogic = new VideoLogic();
        $vret = $videoLogic->addVideoInfo($filename, '', 0, 0, '', 0, 0, 0, $file_uuid);
        if (0 == $ret || false == $vret) {
            return fales;
        } else {
            return true;
        }
    }

    public function listItem($per_page) {
        return $this->fileupload_query->order_by('ctime', 'desc')->paginate($per_page, array('filename', 'uuid', 'flag', 'ctime'));
    }

}

?>
